<html>
<!-- For interactivity we use hidden (off-screen) checkbox as state storage.
 Master table caption changes checkbox state (via <label for=..) and it shows/hide detail table by css rule input+table
 Checkboxes are generated in tenplate-row section of datapacket, because they should be placed right before detail table.
 And all it will also work when viewed in browser too, because we use only standart css methods.
-->
<style>
 {{{defaultstyle}}}
 body {margin: 20px 20px}
 table {
  overflow: hidden;
  display: block;
  transition: height 0.3s;
  transition: opacity 0.3s;
 }

 td, th {border: solid #eee 1px; font-size: 12px; padding: 2 2; }
 th {background: #888; color: white; padding: 5px 5px; draggable: true; resize: horizontal}
 .total td {border: none; border-top: solid #888 1px; font-weight: bold}
 .master {border: none; border-bottom: solid red 1px; font-size: 20px; color: #55c;}
 .tree {display:block; position: absolute; left:-10000; opacity: 0; }
 #orders tr:hover {background: #efe}
 a {text-decoration: none; color: #55c; }
 a:hover {text-decoration: underline}
 input + table {height: 0; opacity: 0.1;}
 input:checked + table {height: auto; opacity: 1;}
</style>
<script type="passcript"></script>
<h2>Customers / Orders</h2>

<DATAPACKET width="900" style="margin: 20 10 10 0">
 <METADATA>
  <FIELDS>
   <FIELD name="COMPANY" class="master" >
    <template-cell>
     <label for="{{CUSTNO}}"><a>{{CUSTNO}} {{COMPANY}}</a></label>
    </template-cell>
   </FIELD>
   <FIELD name="SUMM" class="master" align="right"/>
  </FIELDS>
  <SQL>
   select c.custno, c.company, sum(itemstotal) summ
   from customer c join orders o on o.custno=c.custno
   group by 1,2
   order by company
  </SQL>
 </METADATA>

 <DETAIL id="orders" width="900">
  <METADATA autosort="true">
   <FIELDS>
    <FIELD name="ORDERNO" caption="Order No" group_template="@COMPANY@" total="count(*)" width="10%"/>
    <FIELD name="SALEDATE" caption="Sale Date" width="10%"/>
    <FIELD name="SHIPDATE" caption="Ship Date" width="10%"/>
    <FIELD name="LASTNAME" caption="Employee" width="20%"/>
    <FIELD name="PAYMENTMETHOD" caption="Payment Method" align="center" width="20%"/>
    <FIELD name="ITEMSTOTAL" caption="Total" total="sum" format="# ### ###.00" width="15%"/>
    <FIELD name="AMOUNTPAID" caption="Amount Paid" total="sum" format="# ### ###.00" width="15%"/>
   </FIELDS>
   <SQL>
    select o.orderno, cast(saledate as date) saledate, cast(shipdate as date) shipdate,
     paymentmethod, itemstotal, amountpaid, e.lastname
    from orders o
    join employee e on e.empno=o.empno
    where custno=:custno
    order by 1
   </SQL>
  </METADATA>
 </DETAIL>

<template-row custom="true">
 <![CDATA[
  <table {{{tableattributes}}}>
   <tr>
    {{{_text}}}
   </tr>
  </table>
  <input type="checkbox" class="tree" id="{{CUSTNO}}"/>{{{detail}}}
 ]]>
</template-row>

</DATAPACKET>

</html>
